<?php
/*
  ideal.php for iDEAL Lite v1 2008/12/12
  
  Copyright (c) 2008 e107shop.com

  Daniel Dokter (Webdokter)

  Ideal Lite contributie.

*/

global $e107shop_db_name, $shop_settings, $sql;

$sql = new db;
$sql->db_Select($e107shop_db_name['gateways'], "*", "identifier='ideal'");

while ($row=$sql->db_Fetch()) {
    $ideal_id  = $row['account'];
    $ideal_url = $row['field1'];
    $ideal_key = $row['field2'];
}

switch (e_LANGUAGE) {
    case "Dutch":
        $language = "nl";
        break;
    default:
        $language = "en";
}

$orderid = e107shop_order_id();
$subID = "0";
$paymentType = "ideal";
$total = $total * 100;
$validUntil = date("Y-m-d\TG:i:s\Z", strtotime("+1 week"));
$itemNumber1 = "1";
$itemDescription1 = "Artikel";
$itemQuantity1 = "1";
$itemPrice1 = $total;

### bereken alvast een deel van de shastring
$partOfSha = $partOfSha . $itemNumber1 . $itemDescription1 . $itemQuantity1 . $itemPrice1;

### de complete shastring
$shastring = $ideal_key . $ideal_id . $subID . $total . $orderid . $paymentType . $validUntil . $partOfSha;

### speciale HTML entiteiten verwijderen
$clean_shaString = html_entity_decode($shastring);

### tekens als "\t", "\n", "\r", " " (spaties) mogen niet voorkomen in de string
$not_allowed = array("\t", "\n", "\r", " ");
$clean_shaString = str_replace($not_allowed, "",$clean_shaString);

$shasign = sha1($clean_shaString);


$temp .= "
  
<form action='$ideal_url' method='post' id='form1' name='form1'>
<input type='hidden' name='merchantID' value='$ideal_id'>
<input type='hidden' name='subID' value='0'>
<input type='hidden' name='amount' value='$total'>
<input type='hidden' name='purchaseID' value='$orderid'>
<input type='hidden' name='language' value='$language'>
<input type='hidden' name='currency' value='$currency'>
<input type='hidden' name='description' value='$orderid'>
<input type='hidden' name='hash' value='$shasign'>
<input type='hidden' name='paymentType' value='ideal'>
<input type='hidden' name='validUntil' value='$validUntil'>
<input type='hidden' name='itemNumber1' value='$itemNumber1'>
<input type='hidden' name='itemDescription1' value='$itemDescription1'>
<input type='hidden' name='itemQuantity1' value='$itemQuantity1'>
<input type='hidden' name='itemPrice1' value='$total'>
<input type='hidden' name='urlCancel' value='".$shop_settings['path']."payment_canceled.php'>
<input type='hidden' name='urlSuccess' value='".$shop_settings['path']."payment_accepted.php'>
<input type='hidden' name='urlError' value='".$shop_settings['path']."payment_error.php'>";


if ($language == "nl") {
    $temp .= "<input type='submit' value='Ik wil nu betalen' id='submit2' name='submit2'></form>";
} else {
    $temp .= "<input type='submit' value='I want to pay now' id='submit2' name='submit2'></form>";
}

e107shop_process_order($orderid, "pending", $cart_id, "ideal", $region, $coupon);
$total = $total / 100;
return $temp;
